package com.falcon.web.security;

import com.falcon.authority.api.IUserApi;
import com.falcon.authority.domain.dos.UserDTO;
import com.swan.security.domain.SecurityUserInfo;
import com.swan.security.security.IUserSelector;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/** 通过用户名查询用户详情
 * @author zongf
 * @date 2025-02-19
 */
@Slf4j
@Service
public class SecurityUserSelector implements IUserSelector {

    @Autowired
    private IUserApi userApi;

    @Override
    public SecurityUserInfo selectByUsername(String username) {
        UserDTO userDTO = this.userApi.queryUserByUsername(username);
        return Objects.isNull(userDTO) ? null : new SecurityUserInfo(userDTO.getId(), username, userDTO.getPassword());
    }
}
